/*
 * @lc app=leetcode.cn id=24 lang=javascript
 *
 * [24] 两两交换链表中的节点
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */

var swapPairs = function(head) {
    const VNode = new ListNode(-1, head);
    let tem = VNode;
    while(tem.next && tem.next.next) {
        const node1 = tem.next;
        const node2 = tem.next.next;
        tem.next = node2;
        node1.next = node2.next;
        node2.next = node1;
        tem = node1;
    }  
    return VNode.next;
};
// @lc code=end

